#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n;
int stk[N], tt;

int main() {
	cin >> n;
	while (n--) {
		int x;
		cin >> x;
		while (tt > 0 && stk[tt] >= x) {
			tt--;
		}
		if (tt == 0) {
			cout << "-1" << ' ';
		} else {
			cout << stk[tt] << ' ';
		}
		stk[++tt] = x;
	}
	return 0;
}